/**
 * 
 */
package com.arx.script;

import com.arx.character.NPC;
import com.arx.character.Player;
import com.arx.common.Common;
import com.arx.common.GlobalConsts;
import com.arx.interactive.Interactive;
import com.arx.interactive.InteractiveObject;
import com.arx.script.flyweight.ScriptObject;

/**
 * @author Donald
 *
 */
abstract class ScriptWorkEventAGBase extends ScriptWorkEventBase {
	protected void handleEventAthruG(final ScriptObject es, 
			final ScriptObject esss, final InteractiveObject io,
			final String temp, String cmd, int pos, byte ret, final int msg, final String evname) {
		switch (temp.charAt(0)) {
			case 'A':
				if (temp.equals("ACCEPT")) {
					ret = GlobalConsts.ACCEPT;
					ClearSubStack(es);
					if (super.isNEED_DEBUG()) {
						super.DEBUG_Notify("  ACCEPT");
					}
					sendScriptEventFinishDebug(msg, evname, cmd);
					break;
				} else if (temp.equals("ADDBAG")) {
					Player.getInstance().ARX_PLAYER_AddBag();
					if (super.isNEED_DEBUG()) {
						cmd = "ADD_BAG ";
						super.buildAndDebug(cmd, new String[]{cmd, temp}, 
								false);
					}
				} else if (temp.equals("ACTIVATEPHYSICS")) {
					// ARX_INTERACTIVE_ActivatePhysics(GetInterNumio != null);
				} else if (temp.equals("ADDXP")) {
					pos = GetNextWord(es, pos, temp);
					float val = GetVarValueInterpretedAsFloat(temp, esss, io);
					Player.getInstance().ARX_PLAYER_Modify_XP((long)val);
					if (super.isNEED_DEBUG()) {
						cmd = "ADD_XP ";
						super.buildAndDebug(cmd, new String[]{cmd, temp}, 
								false);
					}
				} else if (temp.equals("ADDGOLD")) {
					pos = GetNextWord(es, pos, temp);
					float val = GetVarValueInterpretedAsFloat(temp, esss, io);

					if (val != 0) {
						//ARX_SOUND_PlayInterface(SND_GOLD);
					}


					val = Common.getInstance().checkLongValue(val);
					Player.getInstance().ARX_PLAYER_AddGold((long) val);
					if (super.isNEED_DEBUG()) {
						cmd = "ADD_GOLD ";
						super.buildAndDebug(cmd, new String[]{cmd, temp}, 
								false);
					}
				} else if (temp.equals("ATTRACTOR")) {
					pos = GetNextWord(es, pos, temp);
					long t = Interactive.getInstance().GetTargetByNameTarget(temp);
					if (t == -2) {
						t = Interactive.getInstance().getInterNum(io);
					}
					pos = GetNextWord(es, pos, temp);
					float val = 0.f;
					float val2 = 0.f;

					if (temp.equalsIgnoreCase("OFF")) {
						val = GetVarValueInterpretedAsFloat(temp, esss, io);
						pos = GetNextWord(es, pos, temp);
						val2 = GetVarValueInterpretedAsFloat(temp, esss, io);
					}

					// ARX_SPECIAL_ATTRACTORS_Add(t, val, val2);
				} else if (temp.equals("AMBIANCE")) {
					float volume = 1f;
					if (super.isNEED_DEBUG()) {
						cmd = "AMBIANCE ";
					}
					pos = GetNextWord(es, pos, temp);
					if (super.isNEED_DEBUG()) {
						super.buildAndDebug(cmd, new String[]{cmd, temp, " "}, 
								false);
					}
					if (temp.charAt(0) == '-') {
						if (super.charInIgnoreCase(temp, 'V')) {
							pos = GetNextWord(es, pos, temp);
							if (super.isNEED_DEBUG()) {
								super.buildAndDebug(cmd, new String[]{cmd, temp, " "}, 
										false);
							}
							volume = GetVarValueInterpretedAsFloat(temp, esss, io);
							pos = GetNextWord(es, pos, temp);
							if (super.isNEED_DEBUG()) {
								super.buildAndDebug(cmd, new String[]{cmd, temp, " "}, 
										false);
							}
							//ARX_SOUND_PlayScriptAmbiance(temp, ARX_SOUND_PLAY_LOOPED, volume * DIV100);
						} else if (super.charInIgnoreCase(temp, 'N')) {
							pos = GetNextWord(es, pos, temp);
							if (super.isNEED_DEBUG()) {
								super.buildAndDebug(cmd, new String[]{cmd, temp, " "}, 
										false);
							}
							//ARX_SOUND_PlayScriptAmbiance(temp, ARX_SOUND_PLAY_ONCE);
						} else if (super.charInIgnoreCase(temp, 'M')) {
							String temp2;
							pos = GetNextWord(es, pos, temp2);
							if (super.isNEED_DEBUG()) {
								super.buildAndDebug(cmd, new String[]{cmd, temp2, " "}, 
										false);
							}
							//ARX_SOUND_SetAmbianceTrackStatus(temp, temp2, 1); //1 = Mute
							pos = GetNextWord(es, pos, temp);
							if (super.isNEED_DEBUG()) {
								super.buildAndDebug(cmd, new String[]{cmd, temp, " "}, 
										false);
							}
						} else if (super.charInIgnoreCase(temp, 'U')) {
							String temp2;
							pos = GetNextWord(es, pos, temp2);
							if (super.isNEED_DEBUG()) {
								super.buildAndDebug(cmd, new String[]{cmd, temp2, " "}, 
										false);
							}
							//ARX_SOUND_SetAmbianceTrackStatus(temp, temp2, 0);//0 = unmute
							pos = GetNextWord(es, pos, temp);
							if (super.isNEED_DEBUG()) {
								super.buildAndDebug(cmd,
										new String[]{cmd, temp, " "}, 
										false);
							}
						}
					} else if (temp.equalsIgnoreCase("KILL")) {
						//ARX_SOUND_KillAmbiances();
					} else {
						//ARX_SOUND_PlayScriptAmbiance(temp);
					}
				} else if (temp.equals("ANCHORBLOCK")) {
					pos = GetNextWord(es, pos, temp);
					if (io != null) {
						if ((temp.equalsIgnoreCase("ON")) || (temp.equalsIgnoreCase("YES"))) {
							//ANCHOR_BLOCK_By_IO(io, 1);
						} else {
							//ANCHOR_BLOCK_By_IO(io, 0);
						}
					}
				} else if (temp.equals("ATTACHNPCTOPLAYER")) {
					if (super.isNEED_DEBUG()) {
						super.buildAndDebug(cmd,
								new String[]{"ATTACH_NPC_TO_PLAYER ...OBSOLETE..."}, 
								false);
					}
				} else if (temp.equals("ATTACH")) {
					if (super.isNEED_DEBUG()) {
						cmd = "ATTACH ";
					}
					String temp1;
					String temp2;
					pos = GetNextWord(es, pos, temp); // Source IO
					if (super.isNEED_DEBUG()) {
						super.buildAndDebug(cmd, new String[]{cmd, temp, " "}, 
								false);
					}
					long t = Interactive.getInstance().GetTargetByNameTarget(temp);
					if (t == -2) {
						t = Interactive.getInstance().getInterNum(io); //self
					}
					pos = GetNextWord(es, pos, temp1); // source action_point
					if (super.isNEED_DEBUG()) {
						super.buildAndDebug(cmd, new String[]{cmd, temp1, " "}, 
								false);
					}
					pos = GetNextWord(es, pos, temp); // target IO
					long t2 = Interactive.getInstance().GetTargetByNameTarget(temp);
					if (super.isNEED_DEBUG()) {
						super.buildAndDebug(cmd, new String[]{cmd, temp, " "}, 
								false);
					}
					if (t2 == -2) {
						t2 = Interactive.getInstance().getInterNum(io); //self
					}
					pos = GetNextWord(es, pos, temp2); // target action_point
					if (super.isNEED_DEBUG()) {
						super.buildAndDebug(cmd, new String[]{cmd, temp2, " "}, 
								false);
					}
					/*
					if (ARX_INTERACTIVE_Attach(t, t2, temp1, temp2)) {
						if (super.isNEED_DEBUG()) {
							strcat(cmd, "--> success");
						}
					} else if (super.isNEED_DEBUG()) {
						strcat(cmd, "--> failure");
					}
					*/
				}
				break;
			case 'B':
				if (temp.equals("BEHAVIOR")) {
					int behavior = 0; //GlobalConsts.BEHAVIOUR_NONE;
					float behavior_param = 0.f;
					pos = GetNextWord(es, pos, temp);
					if (super.isNEED_DEBUG()) {
						super.buildAndDebug(cmd, 
								new String[]{"BEHAVIOR ", temp}, false);
					}
					if (temp.equalsIgnoreCase("STACK")) {
						NPC.getInstance().ARX_NPC_Behaviour_Stack(io);
					} else if (temp.equalsIgnoreCase("UNSTACK")) {
						NPC.getInstance().ARX_NPC_Behaviour_UnStack(io);
					} else if (temp.equalsIgnoreCase("UNSTACKALL")) {
						NPC.getInstance().ARX_NPC_Behaviour_Reset(io);
					} else {
						if (temp.charAt(0) == '-') {
							if (super.charInIgnoreCase(temp, 'L')) {
								behavior |= GlobalConsts.BEHAVIOUR_LOOK_AROUND;
							}
							if (super.charInIgnoreCase(temp, 'S')) {
								behavior |= GlobalConsts.BEHAVIOUR_SNEAK;
							}
							if (super.charInIgnoreCase(temp, 'D'))
								behavior |= GlobalConsts.BEHAVIOUR_DISTANT;
							if (super.charInIgnoreCase(temp, 'M'))
								behavior |= GlobalConsts.BEHAVIOUR_MAGIC;
							if (super.charInIgnoreCase(temp, 'F'))
								behavior |= GlobalConsts.BEHAVIOUR_FIGHT;
							if (super.charInIgnoreCase(temp, 'A'))
								behavior |= GlobalConsts.BEHAVIOUR_STARE_AT;
							if (super.charIn(temp, '0') 
									&& io != null
									&& (io.hasIoFlag(GlobalConsts.IO_NPC))) {
								io.getNpcdata().setTactics((byte) 0);
							}
							if (super.charIn(temp, '1') 
									&& io != null 
									&& (io.hasIoFlag(GlobalConsts.IO_NPC))) {
								io.getNpcdata().setTactics((byte) 0);
							}
							if (super.charIn(temp, '2') 
									&& io != null 
									&& (io.hasIoFlag(GlobalConsts.IO_NPC))) {
								io.getNpcdata().setTactics((byte) 0);
							}
							pos = GetNextWord(es, pos, temp);
							if (super.isNEED_DEBUG()) {
								super.buildAndDebug(cmd, 
										new String[]{cmd, temp}, false);
							}
						}


						if (temp.equalsIgnoreCase("GO_HOME")) {
							behavior |= GlobalConsts.BEHAVIOUR_GO_HOME;
						} else if (temp.equalsIgnoreCase("FRIENDLY")) {
							if (io != null 
									&& (io.hasIoFlag(GlobalConsts.IO_NPC))) {
								io.getNpcdata().setMovemode(GlobalConsts.NOMOVEMODE);
							}
							behavior |= GlobalConsts.BEHAVIOUR_FRIENDLY;
						} else if (temp.equalsIgnoreCase("MOVE_TO")) {
							if (io != null && (io.hasIoFlag(GlobalConsts.IO_NPC))) {
								io.getNpcdata().setMovemode(GlobalConsts.WALKMODE);
							}

							behavior |= GlobalConsts.BEHAVIOUR_MOVE_TO;
						} else if (temp.equalsIgnoreCase("FLEE")) {
							behavior |= GlobalConsts.BEHAVIOUR_FLEE;
							pos = GetNextWord(es, pos, temp);
							behavior_param = GetVarValueInterpretedAsFloat(temp, esss, io);

							if (io != null && (io.hasIoFlag(GlobalConsts.IO_NPC))) {
								io.getNpcdata().setMovemode(GlobalConsts.RUNMODE);
							}
						} else if (temp.equalsIgnoreCase("LOOK_FOR")) {
							behavior |= GlobalConsts.BEHAVIOUR_LOOK_FOR;
							pos = GetNextWord(es, pos, temp);
							behavior_param = GetVarValueInterpretedAsFloat(temp, esss, io);

							if (io != null && (io.hasIoFlag(GlobalConsts.IO_NPC))) {
								io.getNpcdata().setMovemode(GlobalConsts.WALKMODE);
							}
						} else if (temp.equalsIgnoreCase("HIDE")) {
							behavior |= GlobalConsts.BEHAVIOUR_HIDE;
							pos = GetNextWord(es, pos, temp);
							behavior_param = GetVarValueInterpretedAsFloat(temp, esss, io);

							if (io != null && (io.hasIoFlag(GlobalConsts.IO_NPC))) {
								io.getNpcdata().setMovemode(GlobalConsts.WALKMODE);
							}
						} else if (temp.equalsIgnoreCase("WANDER_AROUND")) {
							behavior |= GlobalConsts.BEHAVIOUR_WANDER_AROUND;
							pos = GetNextWord(es, pos, temp);
							behavior_param = GetVarValueInterpretedAsFloat(temp, esss, io);

							if (io != null && (io.hasIoFlag(GlobalConsts.IO_NPC))) {
								io.getNpcdata().setMovemode(GlobalConsts.WALKMODE);
							}
						} else if (temp.equalsIgnoreCase("GUARD")) {
							behavior |= GlobalConsts.BEHAVIOUR_GUARD;
							if (io != null) {
								io.setTargetinfo(-2);

								if (io.hasIoFlag(GlobalConsts.IO_NPC)) {
									io.getNpcdata().setMovemode(GlobalConsts.NOMOVEMODE);
								}
							}
						}
						if (io != null && io.hasIoFlag(GlobalConsts.IO_NPC)) {
							behavior_param = 
									Common.getInstance().checkLongValue(
											behavior_param);
							NPC.getInstance().ARX_NPC_Behaviour_Change(io, behavior, (long) behavior_param);
						}
					}
				}
				/*
				if (temp.equals("BOOK")) {
					pos = GetNextWord(es, pos, temp);
					if (temp.charAt(0) == '-') {
						if (super.charInIgnoreCase(temp, 'A')) { //MAGIC
							Book_Mode = 2;
						}
						if (super.charInIgnoreCase(temp, 'E')) { //Equip
							Book_Mode = 1;
					}
						if (super.charInIgnoreCase(temp, 'M')) { //Map
							Book_Mode = 3;
				}
						pos = GetNextWord(es, pos, temp);
					}

					if (temp.equalsIgnoreCase("OPEN")) {
						ARX_INTERFACE_BookOpenClose(1);
					} else if (temp.equalsIgnoreCase("CLOSE")) {
						ARX_INTERFACE_BookOpenClose(2);
					}
				}
				*/
				break;
			case 'C':
				if (temp.equals("CINE")) { //CAMERA_ACTIVATE
					/*
					long preload = 0;
					if (super.isNEED_DEBUG()) {
						cmd = "CINE ";
					}
					pos = GetNextWord(es, pos, temp);
					if (super.isNEED_DEBUG()) {
						strcat(cmd, temp);
					}
					if (temp.charAt(0) == '-') {
						if (iCharIn(temp, 'P'))
							preload = 1;
						pos = GetNextWord(es, pos, temp);
					}
					if (temp.equalsIgnoreCase("KILL")) {
						DANAE_KillCinematic();
					}
					else if (temp.equalsIgnoreCase("PLAY")) {
						PLAY_LOADED_CINEMATIC = 1;
						ARX_TIME_Pause();
					} else {
						{
							char temp1[256];
							char temp2[256];
							sprintf(temp1, "%sGraph\\interface\\illustrations\\", Project.workingdir);
							strcpy(temp2, temp1);
							strcat(temp2, temp);
							strcat(temp2, ".cin");
							strcat(temp, ".cin");

							if (PAK_FileExist(temp2)) {
								strcpy(WILL_LAUNCH_CINE, temp);
								CINE_PRELOAD = preload;
							}
						}
					}
					*/
				} else if (temp.equals("COLLISION")) {
					pos = GetNextWord(es, pos, temp);
					if (super.isNEED_DEBUG()) {
						cmd = "COLLISION ";
						super.buildAndDebug(cmd, 
								new String[]{cmd, temp}, false);
					}
					if (io != null) {
						if (temp.equalsIgnoreCase("ON")
								|| temp.equalsIgnoreCase("YES")) {
							if (io.hasIoFlag(GlobalConsts.IO_NO_COLLISIONS)) {
								long col = 0;

								for (long kkk = 0; kkk < inter.nbmax; kkk++)
								{
									InteractiveObject ioo = inter.iobj[kkk];

									if (ioo) {
										if (IsCollidingIO(io, ioo))
										{
											InteractiveObject oes = EVENT_SENDER;
											EVENT_SENDER = ioo;
											Stack_SendIOScriptEvent(io, SM_COLLISION_ERROR_DETAIL, "", null);
											EVENT_SENDER = oes;
											col = 1;
										}
									}
								}

								if (col) {
									InteractiveObject oes = EVENT_SENDER;
									EVENT_SENDER = null;
									Stack_SendIOScriptEvent(io, SM_COLLISION_ERROR, "", null);
									EVENT_SENDER = oes;
								}
							}

							io->ioflags &= ~IO_NO_COLLISIONS;
						} else {
							io.assignIOFlags(GlobalConsts.IO_NO_COLLISIONS);
						}
					}
				} else if (temp.equals("CAMERACONTROL")) {
					pos = GetNextWord(es, pos, temp);


					if (super.isNEED_DEBUG()) {
						cmd = "CAMERA_CONTROL ";
						strcat(cmd, temp);
					}



					if (temp.equalsIgnoreCase("ON")) CAMERACONTROLLER = io;
					else CAMERACONTROLLER = null;
				} else if (temp.equals("CONVERSATION")) {
					pos = GetNextWord(es, pos, temp);


					if (super.isNEED_DEBUG())
					{
						cmd = "CONVERSATION ";
						strcat(cmd, temp);
					}


					long nb_people = 0;

					if (temp.charAt(0) == '-')
					{
						if (CharIn(temp, '0')) nb_people = 0;

						if (CharIn(temp, '1')) nb_people = 1;

						if (CharIn(temp, '2')) nb_people = 2;

						if (CharIn(temp, '3')) nb_people = 3;

						if (CharIn(temp, '4')) nb_people = 4;

						if (CharIn(temp, '5')) nb_people = 5;

						if (CharIn(temp, '6')) nb_people = 6;

						if (CharIn(temp, '7')) nb_people = 7;

						if (CharIn(temp, '8')) nb_people = 8;

						if (CharIn(temp, '9')) nb_people = 9;

						pos = GetNextWord(es, pos, temp);


						if (super.isNEED_DEBUG())
						{
							strcat(cmd, " ");
							strcat(cmd, temp);
						}


					}

					if (temp.equals("ON"))
					{
						ARX_CONVERSATION = 1;
					}
					else
					{
						ARX_CONVERSATION = 0;
					}

					if ((nb_people) && ARX_CONVERSATION)
					{
						main_conversation.actors_nb = nb_people;

						for (long j = 0; j < nb_people; j++)
						{
							pos = GetNextWord(es, pos, temp);


							if (super.isNEED_DEBUG())
							{
								strcat(cmd, " ");
								strcat(cmd, temp);
							}


							long t = GetTargetByNameTarget(temp);

							if (t == -2) //self
							{
								for (long k = 0; k < inter.nbmax; k++)
								{
									if (io == Interactive.getInstance().getInteractiveObject(k))
									{
										t = k;
										break;
									}
								}
							}

							main_conversation.actors[j] = t;
						}
					}
				}
				else if (temp.equals("CAMERAACTIVATE"))
				{
					FRAME_COUNT = -1;
					pos = GetNextWord(es, pos, temp);


					if (super.isNEED_DEBUG())
					{
						cmd = "CAMERA_ACTIVATE ";
						strcat(cmd, temp);
					}



					if (temp.equalsIgnoreCase("NONE"))
					{
						MasterCamera.exist = 0;
					}
					else
					{
						FRAME_COUNT = 0;
						long t = GetTargetByNameTarget(temp);

						if (t == -2) t = GetInterNumio != null;

						if (t != -1)
						{
							if (Interactive.getInstance().getInteractiveObject(t)->ioflags & IO_CAMERA)
							{
								MasterCamera.exist |= 2;
								MasterCamera.want_io = Interactive.getInstance().getInteractiveObject(t);
								MasterCamera.want_aup = (ARX_USE_PATH *)Interactive.getInstance().getInteractiveObject(t)->usepath;
								MasterCamera.want_cam = &Interactive.getInstance().getInteractiveObject(t)->_camdata->cam;
							}

						}
					}
				}
				else if (temp.equals("CAMERASMOOTHING")) {
					/*
					pos = GetNextWord(es, pos, temp);


					if (super.isNEED_DEBUG()) {
						cmd = "CAMERA_SMOOTHING ";
						strcat(cmd, temp);
					}
					if (io != null) {
						if (io.hasIoFlag(GlobalConsts.IO_CAMERA)) {
							float fo = GetVarValueInterpretedAsFloat(temp, esss, io);
							EERIE_CAMERA * cam = (EERIE_CAMERA *)io->_camdata;
							cam->smoothing = fo;
						}
					}
					*/
				} else if (temp.equals("CINEMASCOPE")) {
					/*
					pos = GetNextWord(es, pos, temp);


					if (super.isNEED_DEBUG())
					{
						cmd = "CINEMASCOPE ";
						strcat(cmd, temp);
					}


					long smooth = 0;

					if (temp.charAt(0) == '-')
					{
						if ((temp.charAt(1) == 's') || (temp.charAt(1) == 'S'))
						{
							smooth = 1;
						}

						pos = GetNextWord(es, pos, temp);


						if (super.isNEED_DEBUG())
						{
							strcat(cmd, " ");
							strcat(cmd, temp);
						}


					}

					if (temp.equalsIgnoreCase("ON"))
					{
						ARX_INTERFACE_SetCinemascope(1, smooth);
					}
					else ARX_INTERFACE_SetCinemascope(0, smooth);
					*/
				} else if (temp.equals("CAMERAFOCAL")) {
					/*
					pos = GetNextWord(es, pos, temp);


					if (super.isNEED_DEBUG())
					{
						cmd = "CAMERA_FOCAL ";
						strcat(cmd, temp);
					}



					if (io != null)
					{
						if (io.hasIoFlag(GlobalConsts.IO_CAMERA))
						{
							float fo = GetVarValueInterpretedAsFloat(temp, esss, io);
							EERIE_CAMERA * cam = (EERIE_CAMERA *)io->_camdata;
							cam->focal = fo;

							if (cam->focal < 100) cam->focal = 100;
							else if (cam->focal > 800) cam->focal = 800;
						}
					}
					*/
				} else if (temp.equals("CAMERATRANSLATETARGET")) {
					/*
					char temp2[64];
					char temp3[64];

					pos = GetNextWord(es, pos, temp);
					pos = GetNextWord(es, pos, temp2);
					pos = GetNextWord(es, pos, temp3);

					if (io != null)
					{
						if (io.hasIoFlag(GlobalConsts.IO_CAMERA))
						{
							EERIE_3D fo;
							fo.x = GetVarValueInterpretedAsFloat(temp, esss, io);
							fo.y = GetVarValueInterpretedAsFloat(temp2, esss, io);
							fo.z = GetVarValueInterpretedAsFloat(temp3, esss, io);
							EERIE_CAMERA * cam = (EERIE_CAMERA *)io->_camdata;
							cam->translatetarget.x = fo.x;
							cam->translatetarget.y = fo.y;
							cam->translatetarget.z = fo.z;
						}
					}



					if (super.isNEED_DEBUG()) sprintf(cmd, "CAMERA_TRANSLATE_TARGET %s %s %s", temp, temp2, temp3);

					*/
				} else if (temp.equals("CLOSESTEALBAG")) {
					if (io != null && (io.hasIoFlag(GlobalConsts.IO_NPC)))
					{
						if (player.Interface & INTER_STEAL)
						{
							InteractiveObject pio = null;

							if (SecondaryInventory != null)
							{
								pio = (InteractiveObject)SecondaryInventory->io;
							}
							else if (player.Interface & INTER_STEAL)
							{
								pio = ioSteal;
							}

							if ((pio != null) && (pio == ioSteal))
							{
								InventoryDir = -1;
								SendIOScriptEvent(pio, SM_INVENTORY2_CLOSE, "");
								TSecondaryInventory = SecondaryInventory;
								SecondaryInventory = null;
							}

						}
					}
				}
				break;
			case 'E':
				if (temp.equals("ELSE")) {
					pos = SkipNextStatement(es, pos);
					if (super.isNEED_DEBUG()) {
						sprintf(cmd, "ELSE");
					}
				} else if (temp.equals("ENDINTRO")) {
					ARX_INTERFACE_EndIntro();
				} else if (temp.equals("ENDGAME")) {
					GlobalConsts.REFUSE_GAME_RETURN = 1;
					if (FINAL_COMMERCIAL_DEMO)
						ARX_INTERFACE_EndIntro();
					else
					{
						ARX_SOUND_MixerStop(ARX_SOUND_MixerGame);
						ARX_MENU_Launch(GDevice);
						ARX_MENU_Clicked_CREDITS();
					}
				}
				else if (temp.equals("EATME"))
				{


					if (super.isNEED_DEBUG()) sprintf(cmd, "EATME");



					if (io != null) // can only kill IOs
					{
						if (io.hasIoFlag(GlobalConsts.IO_ITEM))
						{
							player.hunger += io->_itemdata->food_value * 4;

							if (player.hunger > 100.f) player.hunger = 100.f;
						}

						if ((io.hasIoFlag(GlobalConsts.IO_ITEM)) && (io->_itemdata->count > 1))
						{
							io->_itemdata->count--;
						}
						else
						{
							io->show = SHOW_FLAG_KILLED;
							io->GameFlags &= ~GFLAG_ISINTREATZONE;
							RemoveFromAllInventoriesio != null;
							ARX_DAMAGES_ForceDeath(io, EVENT_SENDER);
						}
					}
				}
				else if (temp.equals("EQUIP"))
				{
					pos = GetNextWord(es, pos, temp);


					if (super.isNEED_DEBUG())
					{
						cmd = "EQUIP ";
						strcat(cmd, temp);
					}


					long unequip = 0;

					if (temp.charAt(0) == '-')
					{
						if (iCharIn(temp, 'R')) unequip = 1;

						pos = GetNextWord(es, pos, temp);


						if (super.isNEED_DEBUG())
						{
							strcat(cmd, " ");
							strcat(cmd, temp);
						}


					}

					long t = GetTargetByNameTarget(temp);

					if (t == -3) t = 0;

					if (ValidIONum(t))
					{
						if (unequip)
						{
							InteractiveObject oes = EVENT_SENDER;
							EVENT_SENDER = Interactive.getInstance().getInteractiveObject(t);
							Stack_SendIOScriptEvent(io, SM_EQUIPOUT, "", null);
							EVENT_SENDER = oes;
							ARX_EQUIPMENT_UnEquip(Interactive.getInstance().getInteractiveObject(t), io);
						}
						else
						{
							InteractiveObject oes = EVENT_SENDER;
							EVENT_SENDER = Interactive.getInstance().getInteractiveObject(t);
							Stack_SendIOScriptEvent(io, SM_EQUIPIN, "", null);
							EVENT_SENDER = oes;
							ARX_EQUIPMENT_Equip(Interactive.getInstance().getInteractiveObject(t), io);
						}
					}
				}

				break;
			case 'F':

				if (temp.equals("FORCEANIM"))
				{
					char temp2[256];
					long num;
					pos = GetNextWord(es, pos, temp2);
					num = GetNumAnim(temp2);

					if (num > -1)
					{
						if (io != null)
							if (io->anims[num] != null)
							{
								ForceAnim(io, io->anims[num]);
								CheckSetAnimOutOfTreatZone(io, 0);
							}
					}



					if (super.isNEED_DEBUG()) sprintf(cmd, "FORCEANIM %s", temp2);


				}
				else if (temp.equals("FORCEANGLE"))
				{
					pos = GetNextWord(es, pos, temp);

					if (io != null)
					{

						io->angle.b = MAKEANGLE(GetVarValueInterpretedAsFloat(temp, esss, io));
					}



					if (super.isNEED_DEBUG()) sprintf(cmd, "FORCEANGLE %s", temp);


				}
				else if (temp.equals("FORCEDEATH"))
				{
					char temp2[256];
					long t;
					pos = GetNextWord(es, pos, temp2);
					MakeUpcase(temp2);

					if ((!strcmp(temp2, "ME")) || (!strcmp(temp2, "SELF")))
					{
						t = GetInterNumio != null;
					}
					else
					{
						t = GetTargetByNameTarget(temp2);

						if (t == -2) t = GetInterNumio != null;
					}

					if (t > 0)
					{
						ARX_DAMAGES_ForceDeath(Interactive.getInstance().getInteractiveObject(t), io);
					}



					if (super.isNEED_DEBUG()) sprintf(cmd, "FORCE_DEATH %s", temp2);


				}

				break;
			case 'G':
				if (temp.equals("GOTO")) {
					if (msg == GlobalConsts.SM_EXECUTELINE) msg = GlobalConsts.SM_DUMMY;

					if ((pos = GetNextWord(es, pos, temp)) == -1)
					{
						ret = GlobalConsts.ACCEPT;
						sendScriptEventFinishDebug(msg, evname, cmd); 
						return ret;
					}

					pos = FindLabelPos(es, temp);

					if (pos == -1) return GlobalConsts.ACCEPT;
					if (super.isNEED_DEBUG()) sprintf(cmd, "GOTO %s", temp);
				} else if (temp.equals("GOSUB")) {
					if (msg == GlobalConsts.SM_EXECUTELINE) msg = SM_DUMMY;

					if ((pos = GetNextWord(es, pos, temp)) == -1) {
						return GlobalConsts.ACCEPT;
					}

					if (!InSubStack(es, pos)) {
						return BIGERROR;
					}

					pos = FindLabelPos(es, temp);

					if (pos == -1) {
						return GlobalConsts.ACCEPT;
					}
					if (super.isNEED_DEBUG()) {
						super.buildAndDebug(cmd,
								new String[]{"GOSUB ", temp}, 
								false);
					}
				} else if (temp.equals("GMODE")) {
					pos = GetNextWord(es, pos, temp);
				}
				break;
		}
	}
}
